


#ifndef PF_UNDO_H
#define PF_UNDO_H

#include <QList>
#include "lx_Export.h"

class PF_UndoCycle;
class PF_Undoable;

/**
 * Undo / redo functionality. The internal undo list consists of
 * PF_UndoCycle entries.
 *
 * @see PF_UndoCycle

 */
class LX_EXPORT PF_Undo {
public:
    PF_Undo();
    virtual ~PF_Undo();

    void addUndoCycle(PF_UndoCycle* i);

    virtual void undo();
    virtual void redo();

    virtual PF_UndoCycle* getUndoCycle();
    virtual PF_UndoCycle* getRedoCycle();

    virtual int countUndoCycles();
    virtual int countRedoCycles();

    virtual void startUndoCycle();
    virtual void addUndoable(PF_Undoable* u);
    virtual void endUndoCycle();

    /**
     * Must be overwritten by the implementing class and delete
     * the given Undoable (unrecoverable). This method is called
     * for Undoables that are no longer in the undo buffer.
     */
    virtual void removeUndoable(PF_Undoable* u) = 0;

    friend std::ostream& operator << (std::ostream& os, PF_Undo& a);

    static bool test();

protected:
    //! List of undo list items. every item is something that can be undone.
    QList<PF_UndoCycle*> undoList;

    /**
     * Index that points to the current position in the undo list.
     * The item it points on will be undone the next time undo is called.
     * The item after will be redone (if there is an item) when redo 
     * is called.
     */
    int undoPointer;

    /**
     * Current undo cycle.
     */
    PF_UndoCycle* currentCycle;

};


/**
 * Stub for testing the PF_Undo class.
 */
#ifdef LXCAD_TEST
class LX_EXPORT PF_UndoStub : public PF_Undo {
    virtual void removeUndoable(PF_Undoable* u) {
        delete u;
        u = NULL;
    }
};
#endif

#endif

